export const createCategoryTree = (self, categoryTree, selectedCategories) => {
  categoryTree.splice(0);
  let categoryList = self.$store.getters.product.classifications;
  let catsLevel1 = categoryList.filter(cat => cat.level == 1);
  let catsLevel2 = categoryList.filter(cat => cat.level == 2);
  let catsLevel3 = categoryList.filter(cat => cat.level == 3);

  catsLevel1.forEach(function (catLevel1, index) {
    let nodesLevel2 = [];
    let selectedCount = 0;
    catsLevel2.forEach(function (catLevel2) {
      if(catLevel2.parentId == catLevel1.id) {
        let nodesLevel3 = [];
        catsLevel3.forEach(function (catLevel3) {
          if(catLevel3.parentId == catLevel2.id) {
            let checked = selectedCategories.includes(catLevel3.id);
            if(checked) {
              selectedCount++;
            }
            let nodeLevel3 = {value: catLevel3.id, title: catLevel3.name, level: catLevel3.level, disabled: catLevel3.type==2, checked: checked};
            nodesLevel3.push(nodeLevel3);
          }
        });
        let nodeLevel2 = {value: catLevel2.id, title: catLevel2.name, level: catLevel2.level, children: nodesLevel3, disabled: catLevel2.type==2};
        nodesLevel2.push(nodeLevel2);
      }
    });
    let nodeLevel1 = {value: catLevel1.id, title: catLevel1.name, level: catLevel1.level, children: nodesLevel2, disabled: catLevel1.type==2, disableCheckbox: catLevel1.type==2, selectedCount: selectedCount};
    categoryTree.push(nodeLevel1);
  });
}
